package com.kai.awt.menu;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

/**
 * @Author Mr.Yan
 * @create 2022/3/20 15:33
 * @description:
 */
public class Demo1 {

    public static void main(String[] args) {
        Frame frame = new Frame("menu");
        TextArea textArea = new TextArea(30, 30);

        MenuBar menuBar = new MenuBar();

        Menu menu1 = new Menu("文件");
        Menu menu2 = new Menu("编辑");
        Menu menu3 = new Menu("注释");

        MenuItem menuItem1 = new MenuItem("复制");
        MenuItem menuItem2 = new MenuItem("粘贴");
        MenuItem menuItem3 = new MenuItem("单行注释",new MenuShortcut(KeyEvent.VK_G,true));
        MenuItem menuItem4 = new MenuItem("多行注释");
        menuItem3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                textArea.append(e.getActionCommand()+"\n");
            }
        });
        menu3.add(menuItem3);
        menu3.add(menuItem4);

        menu2.add(menuItem1);
        menu2.add(menuItem2);
        menu2.add(menu3);

        menuBar.add(menu1);
        menuBar.add(menu2);

        frame.setMenuBar(menuBar);
        frame.add(textArea);
        frame.pack();
        frame.setVisible(true);
    }
}
